//
//  MainViewController.swift
//  3月5的项目
//
//  Created by 哦哦 on 16/3/5.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @objc private func plusBtnDidClick(){
        
        print(__FUNCTION__)
        
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //KVC 给对象提供类似字典的的方式 访问对象的属性
        //系统的tabbar 是只读属性 不能够直接操作
        
        let mainTabbar = MainTabBar()
        
        //添加点击事件
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents:.TouchUpInside)
        
        
        
        
        
        ////        setValue(MainTabBar, forKey: "tabBar")
        setValue(mainTabbar, forKey: "tabBar")
        //添加所有的子视图控制器
        //内部添加
        addChildViewControllers()
        
        
        
    }
    
    
    private func addChildViewControllers(){
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MassageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
        
    }
    //MARK: 添加子视图控制器
    private func addChildViewController(vc:UIViewController,title:String,imageName:String){
        
        //设置title
        vc.title = title
        vc.tabBarItem.title = title
        //tint 色彩
        tabBar.tintColor = UIColor.orangeColor()
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        //设置选中图片
        vc.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        let nav = UINavigationController(rootViewController:vc)
        
        addChildViewController(nav)
    }
    
    
    
}
